package com.tigercel.xiangchengyun.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.tigercel.xiangchengyun.R;
import com.tigercel.xiangchengyun.entity.ImportantNewsEntity;

import java.util.List;

/**
 * Created by wqj on 2018/5/24.
 */
public class ImportantNewsAdapter extends RecyclerView.Adapter<ImportantNewsAdapter.MyViewHolder> {
    private Context mContext;
    private List<ImportantNewsEntity> dataList;

    public ImportantNewsAdapter(Context context, List<ImportantNewsEntity> dataList) {
        mContext = context;
        this.dataList = dataList;
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
                mContext).inflate(R.layout.item_news_important, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.tv.setText("测试新闻" + dataList.get(position).getContent());
        Glide.with(mContext).load(dataList.get(position).getImgUrl()).into(holder.img);
    }


    @Override
    public int getItemCount() {
        return dataList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        TextView tv;
        ImageView img;

        public MyViewHolder(View view) {
            super(view);
            tv = view.findViewById(R.id.tv_news_title);
            img = view.findViewById(R.id.img_news_image);
        }
    }
}
